package initialize

import (
	"context"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

func InitMongoClient(link string, db string) (client *mongo.Client, database *mongo.Database) {
	clientOptions := options.Client().ApplyURI(link)

	client, err := mongo.Connect(context.TODO(), clientOptions)

	if err != nil {
		panic("连接MongoDB失败")
	}

	err = client.Ping(context.TODO(), nil)
	if err != nil {
		panic("Ping => 测试连接失败")
	}
	database = client.Database(db)
	return
}
